package com.hxt.z.web.service.common.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.ObjectUtils;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.hxt.framework.msg.QueryRequestMsg;
import com.hxt.framework.msg.QueryResponseMsg;
import com.hxt.framework.msg.RequestMsg;
import com.hxt.framework.msg.ResponseMsg;
import com.hxt.framework.utils.DateUtil;
import com.hxt.util.CONSTANT;
import com.hxt.util.MinioClientUtils;
import com.hxt.util.POIUtil;
import com.hxt.util.TypeConvert;
import com.hxt.xt.model.TDealer;
import com.hxt.xt.model.TXlsxModel;
import com.hxt.xt.service.base.BaseMgr;
import com.hxt.xt.service.base.msg.Result;
import com.hxt.xt.service.z.bean.SP;
import com.hxt.z.web.service.common.CommonService;
import com.hxt.z.web.service.common.msg.COM10001Req;
import com.hxt.z.web.service.common.msg.COM10002Req;
import com.hxt.z.web.service.common.msg.COM10003Req;
import com.hxt.z.web.service.common.msg.COM10004Req;
import com.hxt.z.web.service.common.msg.COM10005Req;
import com.hxt.z.web.service.common.msg.COM10006Req;
import com.hxt.z.web.service.common.msg.COM10007Req;
import com.hxt.z.web.service.common.msg.COM10008Req;
import com.hxt.z.web.service.common.msg.COM10009Req;
import com.hxt.z.web.service.common.msg.COM10010Req;
import com.hxt.z.web.service.common.msg.COM10011Req;
import com.hxt.z.web.service.common.msg.COM10012Req;
import com.hxt.z.web.service.common.msg.COM10013Req;
import com.hxt.z.web.service.common.msg.COM10014Req;
import com.hxt.z.web.service.common.msg.COM10015Req;
import com.hxt.z.web.service.common.msg.COM10016Req;
import com.hxt.z.web.service.common.msg.COM10017Req;
import com.hxt.z.web.service.common.msg.COM10018Req;
import com.hxt.z.web.service.common.msg.COM10019Req;
import com.hxt.z.web.service.common.msg.COM10020Req;
import com.hxt.z.web.service.common.msg.COM10021Req;
import com.hxt.z.web.service.common.msg.COM10022Req;
import com.hxt.z.web.service.common.msg.COM10023Req;
import com.hxt.z.web.service.common.msg.COM10024Req;
import com.hxt.z.web.service.common.msg.COM10025Req;
import com.hxt.z.web.service.common.msg.COM10026Req;
import com.hxt.z.web.service.common.msg.COM10027Req;
import com.hxt.z.web.service.common.msg.COM10028Req;
import com.hxt.z.web.service.common.msg.COM10029Req;
import com.hxt.z.web.service.common.msg.COM10030Req;
import com.hxt.z.web.service.common.msg.COM10098Req;
import com.hxt.z.web.service.common.msg.COM10099Req;
import com.hxt.z.web.service.common.msg.COM20000Req;
import com.hxt.z.web.service.common.msg.COM30000Req;

@Service
public class CommonServiceImpl extends BaseMgr implements CommonService {

	/**
	 * 测试
	 */
	@Override
	public ResponseMsg<Result> com19999(RequestMsg<COM10099Req> req) throws Exception {

		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {
			rule.commonRule.com19999();
			result.setData(null);
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 查询操作日志
	 */
	@Override
	public ResponseMsg<Result> com20000(RequestMsg<COM20000Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getOperRecord());
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.toString());
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 查询异常日志
	 */
	@Override
	public ResponseMsg<Result> com30000(RequestMsg<COM30000Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getExcepRecord());
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.toString());
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 登录 返回代理商信息
	 */
	@Override
	public ResponseMsg<Result> com10001(RequestMsg<COM10001Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.login(req.getParam().getUserName(), req.getParam().getPassWord()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	@Override
	public ResponseMsg<Result> com10002(RequestMsg<COM10002Req> req) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 查询省
	 */
	@Override
	public ResponseMsg<Result> com10003(RequestMsg<COM10003Req> req) throws Exception {

		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {
			result.setData(rule.commonRule.getProvince());
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 查询市
	 */
	@Override
	public ResponseMsg<Result> com10004(RequestMsg<COM10004Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getCity(req.getParam().getId()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 读取客户excel表头 客户的表头必须要第一行为列名
	 */
	@Override
	public ResponseMsg<Result> com10005(RequestMsg<COM10005Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getSheetColumn(req.getParam().getKey()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 获取产品名称
	 */
	@Override
	public ResponseMsg<Result> com10006(RequestMsg<COM10006Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getProductName());
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 获取产品规格
	 */
	@Override
	public ResponseMsg<Result> com10007(RequestMsg<COM10007Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getModel(req.getParam().getName()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 获取入库单列表
	 */
	@Override
	public ResponseMsg<Result> com10008(RequestMsg<COM10008Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(
					rule.commonRule.getImportXlsInfo(req.getParam().getBeginTime(), req.getParam().getEndTime()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 出库产品--（分为导出，移库）
	 */
	@Override
	public ResponseMsg<Result> com10009(RequestMsg<COM10009Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {

			txStatus = this.txBegin(0);// 开启事务
			int type = req.getParam().getType();
			String id = req.getParam().getId();
			String did = req.getParam().getDid();
			String dname = req.getParam().getDname();
			String scale = req.getParam().getScale();
			String saleMoney = req.getParam().gettSaleMoney();
			String cnt = req.getParam().getCnt();
			String money = req.getParam().getMoney();
			rule.commonRule.outStorage(type, id, did, dname, scale, saleMoney, cnt, money);

			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 导入产品--到mysql数据库
	 */
	@Override
	public ResponseMsg<Result> com10010(RequestMsg<COM10010Req> req) throws Exception {

		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {
			// 校验文件中是否有11位批序号在库存中存在
//			String key = req.getParam().getKey();
//			TXlsxModel txm = rule.tXlsxModelDao.getObjectById(TypeConvert.strToint(xmlTemple));
//			String content = txm.getMc();
//
//			List<String[]> listXMLS = POIUtil.readExcel(key, content);
			

			txStatus = this.txBegin(0);// 开启事务
			Integer curTime = DateUtil.getToday();

			int limitCnt = CONSTANT.COMMON.LIST_SPLIT_CNT;
			rule.commonRule.importAll(req.getParam().getXmlTemple(), req.getParam().getKey(), curTime, limitCnt);

			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 库存列表-按规格名称分组分页
	 */
	@Override
	public QueryResponseMsg<Result> com10011(QueryRequestMsg<COM10011Req> req) throws Exception {
		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		try {

			String name = req.getParam().getName();
			String model = req.getParam().getModel();
			String regName = req.getParam().getRegname();
			String batchNum = req.getParam().getBatchnum();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			Map<String, Object> ret = rule.commonRule.getStorageList(name, model, regName, batchNum);

			result.setData(ret);
			resp.setResult(result);
			Page m = (Page) ret.get("list");
			resp.setTotal(m.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 库存详细
	 */
	@Override
	public QueryResponseMsg<Result> com10012(QueryRequestMsg<COM10012Req> req) throws Exception {
		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		try {

			String model = req.getParam().getModel();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			List<Map<String, Object>> list = rule.commonRule.getStorageDetail(model);

			PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
			result.setData(list);
			resp.setResult(result);
			resp.setTotal((int) pageInfo.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 13.获取标准表头
	 */
	@Override
	public ResponseMsg<Result> com10013(RequestMsg<COM10013Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getMySheet());
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 14. 保存模板
	 */
	@Override
	public ResponseMsg<Result> com10014(RequestMsg<COM10014Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			rule.commonRule.saveXlsTemple(req.getParam().getContent(), req.getParam().getDescd());
			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 15. 模板列表
	 */
	@Override
	public ResponseMsg<Result> com10015(RequestMsg<COM10015Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.xlsTempleList());
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 16. 删除模板
	 */
	@Override
	public ResponseMsg<Result> com10016(RequestMsg<COM10016Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {
			rule.commonRule.delXlsTemple(req.getParam().getIds());
			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 入库列表
	 */
	@Override
	public ResponseMsg<Result> com10017(RequestMsg<COM10017Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(
					rule.commonRule.impStorageListAdmin(req.getParam().getBeginTime(), req.getParam().getEndTime()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 批发时查看-入库存记录-详细
	 */
	@Override
	public ResponseMsg<Result> com10018(RequestMsg<COM10018Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.impStorageListDetail(req.getParam().getId()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 代理商录入
	 */
	@Override
	public ResponseMsg<Result> com10020(RequestMsg<COM10020Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {
			String address = req.getParam().getAddress();
			String city = req.getParam().getCity();
			String linkman = req.getParam().getLinkman();
			String linkphone = req.getParam().getLinkphone();
			String name = req.getParam().getName();
			String photo1 = req.getParam().getPhoto1();
			String photo2 = req.getParam().getPhoto2();
			String province = req.getParam().getProvince();
			int reg_expiry_date = req.getParam().getReg_expiry_date();
			String type = req.getParam().getType();
			String reg_no = req.getParam().getReg_no();

			TDealer td = new TDealer(name, province, city, address, linkman, linkphone, reg_no, reg_expiry_date, photo1,
					photo2, DateUtil.getToday(), "1", 0, type, MinioClientUtils.presignedURL(photo1),
					MinioClientUtils.presignedURL(photo2));

			txStatus = this.txBegin(0);// 开启事务
			rule.commonRule.addDealer(td);
			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 获取代理商
	 */
	@Override
	public QueryResponseMsg<Result> com10021(QueryRequestMsg<COM10021Req> req) throws Exception {

		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		try {

			String name = req.getParam().getName();
			String province = req.getParam().getProvince();
			String city = req.getParam().getCity();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			List<Map<String, Object>> list = rule.commonRule.getDealers(name, province, city);

			PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
			result.setData(list);
			resp.setResult(result);
			resp.setTotal((int) pageInfo.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 代理商录入
	 */
	@Override
	public ResponseMsg<Result> com10022(RequestMsg<COM10022Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {
			String id = req.getParam().getId();

			txStatus = this.txBegin(0);// 开启事务
			rule.commonRule.delDealer(id);
			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 返回备货代理商-type=2
	 */
	@Override
	public ResponseMsg<Result> com10023(RequestMsg<COM10023Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.searchDealer(req.getParam().getType()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 代理商录入
	 */
	@Override
	public ResponseMsg<Result> com10024(RequestMsg<COM10024Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {
			String address = req.getParam().getAddress();
			String city = req.getParam().getCity();
			String linkman = req.getParam().getLinkman();
			String linkphone = req.getParam().getLinkphone();
			String name = req.getParam().getName();
			String photo1 = req.getParam().getPhoto1();
			String photo2 = req.getParam().getPhoto2();
			String province = req.getParam().getProvince();
			int reg_expiry_date = req.getParam().getReg_expiry_date();
			String type = req.getParam().getType();
			String reg_no = req.getParam().getReg_no();
			int id = req.getParam().getId();
			TDealer td = new TDealer(id, name, province, city, address, linkman, linkphone, reg_no, reg_expiry_date,
					photo1, photo2, DateUtil.getToday(), "1", 0, type, MinioClientUtils.presignedURL(photo1),
					MinioClientUtils.presignedURL(photo2));

			txStatus = this.txBegin(0);// 开启事务
			rule.commonRule.editDealer(td);
			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 开票列表
	 */
	@Override
	public QueryResponseMsg<Result> com10025(QueryRequestMsg<COM10025Req> req) throws Exception {
		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		try {

			String dealerId = req.getParam().getDealerId();
			String beginTime = req.getParam().getBeginTime();
			String endTime = req.getParam().getEndTime();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			Map<String, Object> ret = rule.commonRule.InvoiceInfo(dealerId, beginTime, endTime);
			List<Map<String, Object>> list = (List<Map<String, Object>>) ret.get("list");
			PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
			result.setData(ret);
			resp.setResult(result);
			resp.setTotal((int) pageInfo.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 开票
	 */
	@Override
	public ResponseMsg<Result> com10026(RequestMsg<COM10026Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {

			txStatus = this.txBegin(0);// 开启事务
			Integer curTime = DateUtil.getToday();

			rule.commonRule.makeInvoice(req.getParam().getDealerId(), req.getParam().getDealerName(),
					req.getParam().getMoney(), req.getParam().getFiles());

			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 开票编辑
	 */
	@Override
	public ResponseMsg<Result> com10027(RequestMsg<COM10027Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {

			txStatus = this.txBegin(0);// 开启事务
			Integer curTime = DateUtil.getToday();

			rule.commonRule.editInvoice(req.getParam().getId(), req.getParam().getDealerId(),
					req.getParam().getDealerName(), req.getParam().getFiles(), req.getParam().getMoney());

			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 二级出库 t_dealer_storage t_dealer_out_record
	 */
	@Override
	public ResponseMsg<Result> com10028(RequestMsg<COM10028Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		TransactionStatus txStatus = null;
		try {

			txStatus = this.txBegin(0);// 开启事务

			String totalSalePrice = req.getParam().gettSalePrice();
			String cnt = req.getParam().gettCnt();
			List<SP> list = req.getParam().getList();
			String did = req.getParam().getDealerId();
			String dname = req.getParam().getDealerName();
			rule.commonRule.dOutStorage(TypeConvert.strToint(did), dname, totalSalePrice, cnt, list);

			this.txCommit(txStatus);// 提交事务

			result.setData("");
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		} finally {
			if (txStatus != null && !txStatus.isCompleted())
				this.txRollback(txStatus);
		}
	}

	/**
	 * 二级库列表
	 */
	@Override
	public QueryResponseMsg<Result> com10029(QueryRequestMsg<COM10029Req> req) throws Exception {
		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		try {

			String dealerId = req.getParam().getDealerId();
			String name = req.getParam().getName();
			String model = req.getParam().getModel();
			String batchnum = req.getParam().getBatchnum();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			List<Map<String, Object>> list = rule.commonRule.dOutStorageList(dealerId, name, model, batchnum, "2");
			PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
			result.setData(list);
			resp.setResult(result);
			resp.setTotal((int) pageInfo.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 获取移库时管理员 --库存列表
	 * 
	 * @param
	 * @return
	 */
	@Override
	public QueryResponseMsg<Result> com10030(QueryRequestMsg<COM10030Req> req) throws Exception {
		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		List<Map<String, Object>> list = Lists.newArrayList();
		try {
			String type = req.getParam().getType();
			String dealerId = req.getParam().getDealerId();
			String name = req.getParam().getName();
			String model = req.getParam().getModel();
			String batchnum = req.getParam().getBatchnum();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			if ("1".equals(type)) {

				list = rule.commonRule.getStorageListByType(name, model, "", batchnum);

			} else if ("2".equals(type)) {
				list = rule.commonRule.dOutStorageList(dealerId, name, model, batchnum, "2");

			}

			PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
			result.setData(list);
			resp.setResult(result);
			resp.setTotal((int) pageInfo.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	/**
	 * 根据上传的key,返回已签名的url
	 */
	@Override
	public ResponseMsg<Result> com10098(RequestMsg<COM10098Req> req) throws Exception {

		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.presignedURL(req.getParam().getKey()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}

	}

	/**
	 * 跟据token查询用户信息
	 */
	@Override
	public ResponseMsg<Result> com10099(RequestMsg<COM10099Req> req) throws Exception {
		ResponseMsg<Result> resp = new ResponseMsg<Result>();
		Result result = new Result();
		try {

			result.setData(rule.commonRule.getUserByToken(req.getAccessToken()));
			resp.setResult(result);
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

	@Override
	public QueryResponseMsg<Result> com10019(QueryRequestMsg<COM10019Req> req) throws Exception {
		QueryResponseMsg<Result> resp = new QueryResponseMsg<Result>();
		Result result = new Result();
		try {

			String name = req.getParam().getName();
			String model = req.getParam().getModel();
			String batchNum = req.getParam().getBatchnum();
			if (req.getPageIndex() > 0)
				PageHelper.startPage(req.getPageIndex(), req.getPageSize());
			List<Map<String, Object>> list = rule.commonRule.getDOutStorageList(name, model, batchNum);

			PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
			result.setData(list);
			resp.setResult(result);
			resp.setTotal((int) pageInfo.getTotal());
			setResCode(resp, succes);
			return resp;

		} catch (Exception e) {
			e.printStackTrace();
			handleException(resp, e);
			return resp;
		}
	}

}
